﻿using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace ServerUtils.Test
{
    [TestClass]
    public class OperationResultGenericTest
    {
        private static object data = new object();

        [TestMethod]
        public void GivenSucceedOperationResult_MessagePropertyMustBeNull()
        {
            var actual = OperationResult<object>.Succeed(data);

            Assert.IsNull(actual.Message);
        }

        [TestMethod]
        public void GivenSucceedOperationResult_ResultTypePropertyMustBeSucceed()
        {
            var actual = OperationResult<object>.Succeed(data);

            Assert.AreEqual(OperationResultType.Succeed, actual.ResultType);
        }

        [TestMethod]
        public void GivenSucceedOperationResult_DataPropertyMustBeSet()
        {
            var actual = OperationResult<object>.Succeed(data);

            Assert.AreSame(data, actual.Data);
        }

        [TestMethod]
        public void GivenFailedOperationResult_MessagePropertyMustBeSet()
        {
            var actual = OperationResult<object>.Failed("a text {0}", "with parameter");

            Assert.AreEqual("a text with parameter", actual.Message);
        }

        [TestMethod]
        public void GivenFailedOperationResult_ResultTypePropertyMustBeFailed()
        {
            var actual = OperationResult<object>.Failed("a text");

            Assert.AreEqual(OperationResultType.Failed, actual.ResultType);
        }

        [TestMethod]
        public void GivenFailedOperationResult_DataPropertyMustBeNull()
        {
            var actual = OperationResult<object>.Failed("a text");

            Assert.IsNull(actual.Data);
        }

        [TestMethod]
        public void GivenErrorOperationResult_MessagePropertyMustBeSet()
        {
            var actual = OperationResult<object>.Error("a text {0}", "with parameter");

            Assert.AreEqual("a text with parameter", actual.Message);
        }

        [TestMethod]
        public void GivenErrorOperationResult_ResultTypePropertyMustBeError()
        {
            var actual = OperationResult<object>.Error("a text");

            Assert.AreEqual(OperationResultType.Error, actual.ResultType);
        }

        [TestMethod]
        public void GivenErrorOperationResult_DataPropertyMustBeNull()
        {
            var actual = OperationResult<object>.Error("a text");

            Assert.IsNull(actual.Data);
        }
    }
}
